package org.geekbang.dbexcel.mapping;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author 孙红瑞
 * @ClassName DbMapping.java
 * @Description 获取数据库信息
 * @createTime 2021年02月03日 15:27:00
 */
@Mapper
public interface DbMapping {

    /**
     * 获取当前库中所有表信息
     * @return
     */
    @Select("select * from information_schema.TABLES where TABLE_SCHEMA=(select database()) ")
    List<Map<String,String>> listTable();

    /**
     * 根据表名获取表信息
     * @param tableName
     * @return
     */
    @Select("select * from information_schema.TABLES where TABLE_SCHEMA=(select database()) and TABLE_NAME=#{tableName}")
    Map<String,String> tableInfo(String tableName);

    /**
     * 根据表名获取字段信息
     * @param tableName
     * @return
     */
    @Select("select * from information_schema.COLUMNS where TABLE_SCHEMA = (select database()) and TABLE_NAME=#{tableName}")
    List<Map> listTableColumn(String tableName);

    /**
     * 获取建表语句
     * @param tableName
     * @return
     */
    @Select("show create table ${tableName}")
    Map<String,String> createSql(@Param("tableName") String tableName);
}
